package py.edu.ucom.cadira.game.event.war;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.game.war.WarUser;

/**
 * @author largonet
 * 
 */
public class SetBoardEvent extends WarGameEvent {
    private boolean status;
    private WarUser user;

    public SetBoardEvent(WarUser user, boolean status) {
        this.user = user;
        this.status = status;
    }
   
    public SetBoardEvent() {
		
	}

	public WarUser getUser() {
        return user;
    }
    public void setUser(WarUser user) {
        this.user = user;
    }
    /**
     * @return Returns the status.
     */
    public boolean isStatus() {
        return status;
    }
    /**
     * @param status
     *            The status to set.
     */
    public void setStatus(boolean status) {
        this.status = status;
    }
	@Override
	public void fromXML(Document xml) {
		Element root = xml.getRootElement();
		Element boardNode = root.getChild("SetBoardEvent");
		Element statusNode = boardNode.getChild("status");
		status = Boolean.parseBoolean(statusNode.getValue());
		Element userNode = boardNode.getChild("usuario");
		user.fromXml(userNode);
	}
	@Override
	public void toXML(Element root) {
		Element boardNode = new Element("SetBoardEvent");
		Element statusNode = new Element("status");
		statusNode.addContent(String.valueOf(status));
		
		Element userNode = user.toXml();
		
		boardNode.addContent(statusNode);
		boardNode.addContent(userNode);
		
		root.addContent(boardNode);
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof SetBoardEvent)) {
			return false;
		}
		SetBoardEvent otherObj = (SetBoardEvent) obj;
		if (otherObj.getUser().equals(getUser())) {
			return true;
		}
		return false;
	}
}
